package main

import "fmt"

func get0() int32 {
	return 0
}

func getMinus5() int32 {
	return -5
}

func main() {

	y := get0()
	switch y {
	default:
		fmt.Println("default")
		fallthrough
	case 0, 1, 2, 3:
		fmt.Println("0, 1, 2, 3")
		fallthrough
	case 4, 5, 6, 7:
		fmt.Println("4, 5, 6, 7")
	}

	// Switch: 带一个起始语句，无表达式
	switch x := getMinus5(); { // missing switch expression means "true"
	case x < 0:
		fmt.Println(x, "< 0")
	default:
		fmt.Println(x, ">= 0")
	}

	// Switch: 无表达式
	x := getMinus5()
	switch { // missing switch expression means "true"
	case x < y:
		fmt.Println("x < y")
	case x < 10:
		fmt.Println("x < 10")
	case x == 4:
		fmt.Println("x == 4")
	}

	// Switch Type
	var x2 interface{}
	switch i := x2.(type) {
	case nil:
		fmt.Println("x is nil") // type of i is type of x (interface{})
	case int:
		fmt.Println("x is int, ", i) // type of i is int
	case float64:
		fmt.Println("x is float64, ", i) // type of i is float64
	case func(int) float64:
		fmt.Println("x is func, ", i) // type of i is func(int) float64
	case bool, string:
		fmt.Println("type is bool or string") // type of i is type of x (interface{})
	default:
		fmt.Println("don't know the type") // type of i is type of x (interface{})
	}
}
